<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>

<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>问题详情</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="fly,layui,前端社区">
<meta name="description"
	content="">
	<link rel="stylesheet" href="../res/layui/css/layui.css">
	<link rel="stylesheet" href="../res/css/global.css">
	<script src="../res/layui/layui.js"></script>
<%--	<script src="../js/jquery.js"></script>--%>
	<script src="../js/jquery.min.js"></script>
<style type="text/css" rel="stylesheet">
form {
	margin: 0;
}

.editor {
	margin-top: 5px;
	margin-bottom: 5px;
}
</style>

</head>
<body>
<jsp:include page="/WEB-INF/jsp/head.jsp"></jsp:include>
	<div class="main layui-clear">
		<div class="wrap">
			<div class="content detail">
				<div class="fly-panel detail-box">
					<h1>${question.title}</h1>
					<div class="fly-tip fly-detail-hint" data-id="">
						<c:if test="${question.isUp == 1}">
						<span class="fly-tip-stick">置顶帖</span>
							</c:if>
<%--						<span class="jie-admin">--%>
<%--						<a href="">点击置顶</a> </span> <span--%>
<%--							class="layui-btn layui-btn-mini jie-admin"> <a href="">取消置顶</a>--%>
<%--						</span>--%>

							<c:if test="${question.uid == user.uid}">
							<span class="jie-admin" type="del" style="margin-left: 20px;">

							<a href="/ques/deleteQue?qid=${question.qid}">删除该帖</a>
							</span></c:if>

						<div class="fly-list-hint">
							<i class="iconfont" title="回答">&#xe60c;</i> ${answeredCount}
						</div>
					</div>
					<div class="detail-about">
						<a class="jie-user" href=""> <img
							src="../${autor.avatar}" alt="头像"> <cite> ${autor.nickname}
								<em>${question.createtime}发布</em> </cite> </a>
						<div class="detail-hits" data-id="{{rows.id}}">

							 <span class="layui-btn layui-btn-mini jie-admin"><a
								href="#">已完帖</a> </span>
							<span class="layui-btn layui-btn-mini jie-admin" type="collect"
								data-type="add"> <a  id="collectPost" href="javascript:;" onclick="collect()">收藏</a> </span>
							<span class="layui-btn layui-btn-mini jie-admin  layui-btn-danger"
								type="collect" data-type="add"> <a href="javascript:;" onclick="cancel()">取消收藏</a> </span>

						</div>
					</div>
					<div class="detail-body photos" style="margin-bottom: 20px;">
						<p>${question.description}</p>
					</div>
				</div>


				<div class="fly-panel detail-box" style="padding-top: 0;">
					<a name="comment"></a>
					<ul class="jieda photos" id="jieda">
						<c:choose>
							<c:when test="${answerList == null}">
								<li class="fly-none">没有任何回答</li>
							</c:when>
							<c:when test="${answerList != null}">
								<c:forEach items="${answerList}" var="answer">
									<li data-id="12" class="jieda-daan">
										<div class="detail-about detail-about-reply">
											<a class="jie-user" href="javascript:;">
												<img src="${contextPath}/${answer.user.avatar}" alt="">
												<cite> <i>${answer.user.nickname}</i></cite>
											</a>
											<div class="detail-hits">
												<span>${answer.createtime}</span>
											</div>
											<c:if test="${answer.is_accept} == 1">
											<i class="iconfont icon-caina" title="最佳答案"></i></c:if>
										</div>
										<div class="detail-body jieda-body">
											<p>${answer.content}</p>
										</div>
<%--										jieda-zan jieda-zan zanok--%>
										<div class="jieda-reply">
											<c:if test="${answer.flag == 0}">
												<span class="jieda-zan" type="zan"><i
														class="iconfont icon-zan"  onclick="like('${answer.aid}')"></i><em>${answer.likes}</em>
												</span>
											</c:if>
											<c:if test="${answer.flag == 1}">
												<span class="jieda-zan zanok" type="zan"><i
														class="iconfont icon-zan"  onclick="like('${answer.aid}')"></i><em>${answer.likes}</em>
												</span>
											</c:if>
										</div>
									</li>
								</c:forEach>
							</c:when>

						</c:choose>


						<%--<li data-id="13"><a name="item-121212121212"></a>
                            <div class="detail-about detail-about-reply">
                                <a class="jie-user" href=""> <img
                                    src="res/images/uer.jpg" alt=""> <cite> <i>香菇</i>
                                        <em style="color:#FF9E3F">活雷锋</em> </cite> </a>
                                <div class="detail-hits">
                                    <span>刚刚</span>
                                </div>
                            </div>
                            <div class="detail-body jieda-body">
                                <p>蓝瘦</p>
                            </div>
                            <div class="jieda-reply">
                                <span class="jieda-zan" type="zan"><i
                                    class="iconfont icon-zan"></i><em>0</em>
                                </span>
                                <div class="jieda-admin">
                                    <span type="del"><a href="#" class="layui-btn layui-btn-danger layui-btn-small">删除</a></span>
                                    <span class="jieda-accept" type="accept">
                                    <a href="#" class="layui-btn  layui-btn-small">采纳</a></span>
                                </div>
                            </div></li>--%>

						<!-- <li class="fly-none">没有任何回答</li> -->
					</ul>
					<span
										id="toName">@ 压缩(楼主)</span>		
					<div class="layui-form layui-form-pane">
						<form action="${pageContext.servletContext.contextPath}/answers/save" method="post">
							<input type="hidden" name="qid" value="${question.qid}">
							<div class="layui-form-item layui-form-text">
								<div class="layui-input-block">
									<div class="editor">
										<textarea id="L_content" name="content" style="width:690px;height:350px;visibility:hidden;"></textarea>
									</div>
								</div>

							</div>

							<div class="layui-form-item">
								<button class="layui-btn" lay-filter="*" lay-submit>立即回答</button>
							</div>
						</form>
<%--						<form action="${pageContext.servletContext.contextPath}/answers/save", method="post">--%>
<%--							<input type="hidden" name="qid" value="${question.qid}">--%>
<%--							<div class="layui-form-item layui-form-text">--%>
<%--								<div class="layui-input-block">--%>
<%--										<textarea id="L_content" name="content" required--%>
<%--										lay-verify="required" placeholder="我要回答"--%>
<%--										class="layui-textarea fly-editor" style="height: 150px;"></textarea>--%>
<%--								</div>--%>
<%--							</div>--%>
<%--							<input  type="submit" value="提交回答"></input>--%>
<%--&lt;%&ndash;							<div class="layui-form-item">&ndash;%&gt;--%>
<%--&lt;%&ndash;								<input class="layui-btn" type="submit">提交回答</input>&ndash;%&gt;--%>
<%--&lt;%&ndash;							</div>&ndash;%&gt;--%>
<%--						</form>--%>
					</div>
				</div>
			</div>
		</div>


	</div>
 <script type="text/javascript" charset="utf-8" src="../res/js/kindeditor.js"></script>
  <script type="text/javascript">
    KE.show({
        id : 'L_content',
		resizeMode : 1,
        items : [
        'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
        'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
        'insertunorderedlist', 'emoticons', 'image', 'link']
    });

	function collect(){

		$.ajax({
			url : "${pageContext.servletContext.contextPath}/users/collect?qid=${question.qid}",
			type : "get",
			success : function (res) {
					// console.log(res);
					alert(res.msg);
			}
		});
	}

	function cancel(){

		$.ajax({
			url : "${pageContext.servletContext.contextPath}/users/cancel?qid=${question.qid}",
			type : "get",
			success : function (res) {
				// console.log(res);
				alert(res.msg);

			}
		});
	}
	function like(aid){

		$.ajax({
			url : "${pageContext.servletContext.contextPath}/answers/like?aid="+aid,
			type : "get",
			success : function (res) {
				// console.log(res);
				if(res == 200){
					window.location.href = "${pageContext.servletContext.contextPath}/ques/detail?qid="+${question.qid};
				}else {
					alert("请先登录！");
				}
			}
		});
	}
  </script>
</body>
</html>